﻿using System;
using System.Collections;
using System.ComponentModel;

namespace UIT.ScrumTool.Client.Utilities.TaskGridView
{
    public class TaskGV : IDataErrorInfo
    {
        protected int color = 1;
        protected string description = string.Empty;
        protected float estimateStoryPoint = 1;
        protected float estimatedDuration = 0;
        protected float height = 1;
        protected string id = string.Empty;
        protected int importance = 1;
        internal IList m_containingList;
        protected int operatorId = 1;
        protected int projectId = 1;
        protected int sprintId = 1;
        protected string subject = string.Empty;

        public TaskGV()
        {
        }

        public TaskGV(string id, string subject, string description, float estimateStoryPoint, int importance,
                      int operatorId,
                      int sprintId, int projectId, float height, int color, float estimatedDuration)
        {
            this.id = id;
            this.subject = subject;
            this.description = description;
            this.estimateStoryPoint = estimateStoryPoint;
            this.importance = importance;
            this.operatorId = operatorId;
            this.sprintId = sprintId;
            this.projectId = projectId;
            this.height = height;
            this.color = color;
            this.estimatedDuration = estimatedDuration;
        }

        public string ID
        {
            set
            {
                id = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
            get { return id; }
        }

        public float EstimatedDuration
        {
            set
            {
                estimatedDuration = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
            get { return estimatedDuration; }
        }

        public string Subject
        {
            get { return subject; }
            set
            {
                subject = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string Description
        {
            get { return description; }
            set
            {
                description = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public float EstimateStoryPoint
        {
            get { return estimateStoryPoint; }
            set
            {
                estimateStoryPoint = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public int Importance
        {
            get { return importance; }
            set
            {
                importance = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public int OperatorId
        {
            get { return operatorId; }
            set
            {
                operatorId = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public int SprintId
        {
            get { return sprintId; }
            set
            {
                sprintId = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public int ProjectId
        {
            get { return projectId; }
            set
            {
                projectId = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public int Color
        {
            get { return color; }
            set { color = value; }
        }

        public float Height
        {
            get { return height; }
            set
            {
                height = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        #region IDataErrorInfo Members

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get
            {
                string error = string.Empty;

                switch (columnName)
                {
                    case "Subject":
                        {
                            if (String.IsNullOrEmpty(subject))
                                error = "The composer's first name should be specified if possible.";
                            break;
                        }
                }

                return error;
            }
        }

        #endregion

        protected virtual void InvokeListChanged(ListChangedEventArgs e)
        {
            ((TaskBindingListComplete) m_containingList).InvokeOnListChanged(e);
        }
    }
}